package book.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import book.dto.Page;
import book.service.BookService;
import book.service.impl.BookServiceImpl;

/**
 * 
 */
public class BookgetListJsonServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
  
    BookService bookService = new BookServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String pageNO = request.getParameter("pageNO");
		String pageSize = request.getParameter("pageSize");
		
		try {
			
			
			Page bookList = bookService.getBookList(Integer.parseInt(pageNO), Integer.parseInt(pageSize));
			
			String json= JSON.toJSONString(bookList);
			
			response.getWriter().write(json);
			
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		
		
	}

}
